function colorrgba(hex: string, apha: number) {
  hex = hex.replace(/^#/, "");
  // 确保 hex 是 6 位或 8 位长
  if (hex.length === 3) {
    // 如果是 3 位简写形式，扩展为 6 位
    hex = hex
      .split("")
      .map((c) => c + c)
      .join("");
  } else if (hex.length !== 6 && hex.length !== 8) {
    throw new Error("Invalid hex color");
  }

  // 将 16 进制颜色值转换为 10 进制
  const r = parseInt(hex.slice(0, 2), 16);
  const g = parseInt(hex.slice(2, 4), 16);
  const b = parseInt(hex.slice(4, 6), 16);
  // const a = hex.length === 8 ? parseInt(hex.slice(6, 8), 16) / 255 : 1; // 如果有透明度，转换为 0-1 范围

  return `rgba(${r}, ${g}, ${b}, ${apha})`;
}

const style = {
  colorrgba,
};

export default style;
